

int  cpe_refresh_igd_ld_wlanconfiguration(cwmp_t * cwmp, parameter_node_t * param_node, callback_register_func_t callback_reg)
{
    FUNCTION_TRACE();

    if(!param_node)
    {
        return FAULT_CODE_9002;
    }
    parameter_node_t * tmp_param, *tmp_node, *child_param;
    child_param = param_node->child;
    if(child_param)
    {
        for(tmp_param=child_param->next_sibling; tmp_param; )
        {
            cwmp_log_info("refresh LANDevice.{i}.WLANConfiguration node, delete param %s\n", tmp_param->name);
            tmp_node = tmp_param->next_sibling;
            cwmp_model_delete_parameter(tmp_param);
            tmp_param = tmp_node;
        }
        child_param->next_sibling = NULL;

		cwmp_log_info("ready to get lan index");
        int lan_index = get_index_after_paramname(param_node, "LANDevice"); 

        cwmp_log_info("lan index is:%d", lan_index);
		
        parameter_node_t * lan1conn_param;
        cwmp_model_copy_parameter(param_node, &lan1conn_param, 1);
		
        if(lan_index == 2)
        {
             parameter_node_t * lan2conn_param;
             cwmp_model_copy_parameter(param_node, &lan2conn_param, 2);
        }

        cwmp_model_refresh_object(cwmp, param_node, 0, callback_reg); 
    }

    return FAULT_CODE_OK;
}



int cpe_get_igd_ld_wc_ssid(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
    char tmp[64] = {0};

	cfg_get_item("SSID1", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_ssid(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	
	cfg_set("SSID1", value);
	//cfg_save();

	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_enable(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = {0};

	cfg_get_item("wifiEnabled", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_enable(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	
	cfg_set("wifiEnabled", value);
	//cfg_save();

	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_bssid(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[32] = {0};

	cfg_get_item("wifi_mac", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_channel(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = {0};

	cfg_get_item("Channel", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_channel(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	
	cfg_set("Channel", value);
	//cfg_save();

	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_autochannel(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = {0};

	cfg_get_item("Channel", tmp, sizeof(tmp)-1);

	if(strcmp(tmp,"0") == 0)
		*value = pool_pstrdup(pool, "1");
	else
		*value = pool_pstrdup(pool, "0");
	
	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_autochannel(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	if(atoi(value) == 0)
	{
		cfg_set("Channel", value);
		//cfg_save();
	}
	
	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_encryption_mode(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[16] = {0};

	cfg_get_item("AuthMode", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_encryption_mode(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	cfg_set("AuthMode", value);
	//cfg_save();
	
	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_bandwidth(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[32] = {0};

	cfg_get_item("wifi_11n_cap", tmp, sizeof(tmp)-1);
	
	*value = pool_pstrdup(pool, tmp);
	
	if(strcmp(tmp,"1") == 0)
		*value = pool_pstrdup(pool, "20MHz/40MHz");
	else
		*value = pool_pstrdup(pool, "20MHz");
	
	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_bandwidth(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	if(strcmp(value,"20MHz/40MHz") == 0)
		cfg_set("wifi_11n_cap", "1");
	else
		cfg_set("wifi_11n_cap", "0");
	//cfg_save();
	
	return	FAULT_CODE_OK;
}

int cpe_get_igd_ld_wc_psk(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	char tmp[64] = {0};

	cfg_get_item("WPAPSK1", tmp, sizeof(tmp)-1);

	*value = pool_pstrdup(pool, tmp);

	return	FAULT_CODE_OK;
}

int cpe_set_igd_ld_wc_psk(cwmp_t * cwmp, const char * name, const char * value, int length, callback_register_func_t callback_reg)
{
	FUNCTION_TRACE();
	cfg_set("WPAPSK1", value);
	//cfg_save();
	
	return	FAULT_CODE_OK;
}

int  cpe_refresh_igd_ld_wc_wepkey(cwmp_t * cwmp, parameter_node_t * param_node, callback_register_func_t callback_reg)
{
//    FUNCTION_TRACE();

    if(!param_node)
    {
        return FAULT_CODE_9002;
    }
    parameter_node_t * tmp_param, *tmp_node, *child_param;
    child_param = param_node->child;
    if(child_param)
    {
        for(tmp_param=child_param->next_sibling; tmp_param; )
        {
            cwmp_log_info("refresh WLANConfiguration node, delete param %s\n", tmp_param->name);
            tmp_node = tmp_param->next_sibling;
            cwmp_model_delete_parameter(tmp_param);
            tmp_param = tmp_node;
        }
        child_param->next_sibling = NULL;

        int lan_index = get_index_after_paramname(param_node, "LANDevice"); 
        int wlan_cof_index = get_index_after_paramname(param_node, "WLANConfiguration"); 

        if(lan_index == 1)
        {
            parameter_node_t * wlan_conf_param;
            switch(wlan_cof_index)
            {
                case 1: 
                    cwmp_model_copy_parameter(param_node, &wlan_conf_param, 1);
                    break;

                case 2:
                    cwmp_model_copy_parameter(param_node, &wlan_conf_param, 1); 
                    cwmp_model_copy_parameter(param_node, &wlan_conf_param, 2);
                    break;

            }       
            
        }
        else if(lan_index == 2)
        {
            //don't support
            cwmp_log_info("do not support index 2");
        }

        cwmp_model_refresh_object(cwmp, param_node, 0, callback_reg); 
    }

    return FAULT_CODE_OK;
}



int  cpe_refresh_igd_ld_wc_presharekey(cwmp_t * cwmp, parameter_node_t * param_node, callback_register_func_t callback_reg)
{
//    FUNCTION_TRACE();

    if(!param_node)
    {
        return FAULT_CODE_9002;
    }
    parameter_node_t * tmp_param, *tmp_node, *child_param;
    child_param = param_node->child;
    if(child_param)
    {
        for(tmp_param=child_param->next_sibling; tmp_param; )
        {
            cwmp_log_info("refresh WLANConfiguration node, delete param %s\n", tmp_param->name);
            tmp_node = tmp_param->next_sibling;
            cwmp_model_delete_parameter(tmp_param);
            tmp_param = tmp_node;
        }
        child_param->next_sibling = NULL;

        int lan_index = get_index_after_paramname(param_node, "LANDevice"); 
        int wlan_cof_index = get_index_after_paramname(param_node, "WLANConfiguration"); 

        if(lan_index == 1)
        {
            parameter_node_t * wlan_conf_param;
            switch(wlan_cof_index)
            {
                case 1: 
                    cwmp_model_copy_parameter(param_node, &wlan_conf_param, 1);
                    break;

                case 2:
                    cwmp_model_copy_parameter(param_node, &wlan_conf_param, 1); 
                    cwmp_model_copy_parameter(param_node, &wlan_conf_param, 2);
                    break;

            }       
            
        }
        else if(lan_index == 2)
        {
            //don't support
            cwmp_log_info("do not support index 2");
        }

        cwmp_model_refresh_object(cwmp, param_node, 0, callback_reg); 
    }

    return FAULT_CODE_OK;
}

#include "netotherapi.h"

int cpe_get_wlan_bytes_sent(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
    unsigned long long data_send_total = 0;
	char wlan_name[30] = {0};
	char tmp[65] = {0};

	cfg_get_item("wifilan", wlan_name, sizeof(wlan_name));
	getIfStatistic(wlan_name, TXBYTE, &data_send_total);
	sprintf(tmp,"%llu",data_send_total);
	*value = pool_pstrdup(pool, tmp);
    return	FAULT_CODE_OK;
}

int cpe_get_wlan_bytes_received(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
	unsigned long long data_rcv_total = 0;
	char wlan_name[30] = {0};
	char tmp[65] = {0};

	cfg_get_item("wifilan", wlan_name, sizeof(wlan_name));
   	getIfStatistic(wlan_name, RXBYTE, &data_rcv_total); //¶ÁÈ¡½ÓÊÕÊý¾Ý;
	sprintf(tmp,"%llu",data_rcv_total);
	*value = pool_pstrdup(pool, tmp);
    return	FAULT_CODE_OK;
}

int cpe_get_wlan_packets_sent(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
    unsigned long long data_send_total = 0;
	char wlan_name[30] = {0};
	char tmp[65] = {0};

	cfg_get_item("wifilan", wlan_name, sizeof(wlan_name));
	getIfStatistic(wlan_name, TXPACKET, &data_send_total);

	sprintf(tmp,"%llu",data_send_total);
	*value = pool_pstrdup(pool, tmp);

    return	FAULT_CODE_OK;
}

int cpe_get_wlan_packets_received(cwmp_t * cwmp, const char * name, char ** value, pool_t * pool)
{
	FUNCTION_TRACE();
    unsigned long long data_rcv_total = 0;
	char wlan_name[30] = {0};
	char tmp[65] = {0};

	cfg_get_item("wifilan", wlan_name, sizeof(wlan_name));
   	getIfStatistic(wlan_name, RXPACKET, &data_rcv_total); //¶ÁÈ¡½ÓÊÕÊý¾Ý;
	
	sprintf(tmp,"%llu",data_rcv_total);
	*value = pool_pstrdup(pool, tmp);
    return	FAULT_CODE_OK;
}


